package com.gxa.controller;

import com.gxa.common.R;
import com.gxa.common.ResponseData;
import com.gxa.pojo.*;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Controller
@Api(value = "部门数据test",tags = "部门数据接口API")
@RequestMapping(value = "/dept",method = RequestMethod.GET  )
public class DeptController {
    // 查询
//    @Autowired
//    private DeptService deptService;
    @RequestMapping(value = "/queryDeptList",method = RequestMethod.GET)
    @ApiOperation(value = "部门查询接口",notes = "传递当前页码数和每页显示记录数",httpMethod = "GET",response = ResponseData.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码数",required = true,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "pageSize",value = "每页显示条数",required = true,dataType = "String",paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code = 200,message = "请求成功"),
            @ApiResponse(code = 404,message = "找不到页面"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
    @ResponseBody
    public ResponseData queryDeptList(@RequestParam("currentPage") Integer currentPage, @RequestParam("pageSize") Integer pageSize){
        ResponseData rd = new ResponseData();
        rd.setCode(200);
        rd.setMsg("success");
        List<Dept> deptList = new ArrayList<>();
        Dept dept01 = new Dept();
        dept01.setDept_name("技术部");
        dept01.setEmp_tel("123456789");
        Dept dept02 = new Dept();
        dept02.setDept_name("事业部");
        dept02.setEmp_tel("654799312");
        deptList.add(dept01);
        deptList.add(dept02);
        rd.setData(deptList);
        return rd;
//        return deptService.queryDeptList(currentPage,pageSize);
    }
     // 添加部门
    @RequestMapping(value = "/addDept",method = RequestMethod.POST)
    @ApiOperation(value = "添加部门接口",notes = "添加部门信息",httpMethod = "POST", response = ResponseData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public ResponseData addDept(@RequestBody @ApiParam(name = "dept",value = "添加部门信息",required = true) Dept dept){
        ResponseData rd = new ResponseData();
        rd.setCode(200);
        rd.setMsg("success");
        rd.setData(dept);
        return rd;
    }
     //编辑
    @RequestMapping(value = "/updateDept",method = RequestMethod.POST)
    @ApiOperation(value = "编辑部门接口",notes = "编辑部门信息",httpMethod = "POST", response = ResponseData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public ResponseData updateDept(@RequestBody @ApiParam(name = "dept",value = "编辑部门信息",required = true) Dept dept){
        ResponseData rd = new ResponseData();
        rd.setCode(200);
        rd.setMsg("success");
        rd.setData(dept);
        return rd;
    }
     // 删除
     @RequestMapping(value = "/delDept",method = RequestMethod.POST)
     @ApiOperation(value = "删除部门信息接口",notes = "删除部门信息",httpMethod = "POST", response = ResponseData.class)
     @ApiResponses({
             @ApiResponse(code=200,message="请求成功"),
             @ApiResponse(code=404,message="找不到页面"),
             @ApiResponse(code=500,message="后台服务错误")
     })
     @ResponseBody
     public ResponseData delDept(@RequestBody @ApiParam(name = "dept_id",value = "删除部门信息",required = true) Integer dept_id){
         ResponseData rd = new ResponseData();
         if(2 == dept_id){
             rd.setCode(500);
             rd.setMsg("该部门下有二级部门，请删除二级部门在删除该部门");
         }else{
             rd.setCode(200);
             rd.setMsg("success");
         }
         return rd;
     }
     //关键字查找
    @RequestMapping(value = "/searchDeptList",method = RequestMethod.GET)
    @ApiOperation(value = "部门查询接口",notes = "传递当前页码数和每页显示记录数",httpMethod = "GET",response = ResponseData.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前页码数",required = true,dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "pageSize",value = "每页显示条数",required = true,dataType = "String",paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code = 200,message = "请求成功"),
            @ApiResponse(code = 404,message = "找不到页面"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
    @ResponseBody
    public ResponseData searchDeptList(@RequestParam("currentPage") Integer currentPage, @RequestParam("pageSize") Integer pageSize,@RequestParam("keyword")String keyword){
        ResponseData rd = new ResponseData();
        rd.setCode(200);
        rd.setMsg("success");
        List<Dept> deptList = new ArrayList<>();
        Dept dept01 = new Dept();
        dept01.setDept_name("技术部");
        dept01.setEmp_tel("123456789");
        dept01.setDept_level(0);
        Dept dept02 = new Dept();
        dept02.setDept_name("测试部");
        dept02.setEmp_tel("654799312");
        dept02.setDept_level(1);
        deptList.add(dept01);
        deptList.add(dept02);
        rd.setData(deptList);
        return rd;
    }
     //点击查询员工
     @RequestMapping(value = "/queryEmp",method = RequestMethod.GET)
     @ApiOperation(value = "点击查询部门员工接口",notes = "部门员工信息",httpMethod = "GET",response = ResponseData.class)
     @ApiResponses({
             @ApiResponse(code = 200,message = "请求成功"),
             @ApiResponse(code = 404,message = "找不到页面"),
             @ApiResponse(code = 500,message = "后台服务错误")
     })
     @ResponseBody
     public ResponseData queryEmp(@RequestParam("dept_name")String dept_name){
         ResponseData rd = new ResponseData();
         rd.setCode(200);
         rd.setMsg("success");
         List<Emp> empList = new ArrayList<>();
         Emp emp01 = new Emp();
         emp01.setEmp_name("zhangsan");
         emp01.setEmp_dept("事业部");
         emp01.setEmp_height(180.5);
         emp01.setEmp_weight(65.0);
         emp01.setEmp_sex("男");
         emp01.setEmp_tel("111111111");
         Emp emp02 = new Emp();
         emp02.setEmp_name("lisi");
         emp02.setEmp_dept("事业部");
         emp02.setEmp_height(175.0);
         emp02.setEmp_weight(60.0);
         emp02.setEmp_sex("男");
         emp02.setEmp_tel("222222222");
         empList.add(emp01);
         empList.add(emp02);
         rd.setData(empList);
         return rd;
     }
    // 查询部门组织架构
    @RequestMapping(value = "/queryDept",method = RequestMethod.GET)
    @ApiOperation(value = "查询部门组织架构接口",notes = "查询部门组织架构信息",httpMethod = "GET",response = ResponseData.class)
    @ApiResponses({
            @ApiResponse(code = 200,message = "请求成功"),
            @ApiResponse(code = 404,message = "找不到页面"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
    @ResponseBody
    public ResponseData queryDept(){
        ResponseData rd = new ResponseData();
        rd.setCode(200);
        rd.setMsg("success");
        List<Dept> deptList = new ArrayList<>();
        Dept dept01 = new Dept();
        dept01.setDept_name("技术部");
        dept01.setDept_level(0);
        Dept dept02 = new Dept();
        dept02.setDept_name("事业部");
        dept02.setDept_level(1);
        deptList.add(dept01);
        deptList.add(dept02);
        rd.setData(deptList);
        return rd;
    }


}
